Pretty Urls turns ugly when i click commandbutton without immediate attribute.
Splash › Forums › PrettyFaces Users › Pretty Urls turns ugly when i click commandbutton without immediate attribute.
Tagged: commandbutton, converter, immediate, Prettyfaces, URL
This topic contains 6 replies, has 2 voices, and was last updated by caglar 1 year ago.
-
AuthorPosts
-
May 8, 2012 at 6:01 pm #18358
Hello; first of all, i’m new to java and jsf. i’m using jsf 2.1.1, Prettyfaces 3.3.2 and Primefaces 3.0.M4.
Here is the summary of my code:
pretty-config.xml :
<url-mapping id=”question”>
<pattern value=”/question/#{question}” />
<view-id value=”/faces/questions/question.xhtml” />
</url-mapping>
summary of question.xhtml:
<f:metadata>
<f:viewParam name=”question” value=”#{questionBean.selectedQuestion}”
converter=”questionConverter” />
</f:metadata>
<h:form id=”form”>
<div id=”question”>
………………
</div>
<div id=”writeanswer”>
<p:editor value=”#{questionBean.answer}” width=”920″ required=”true”
requiredMessage=”fgfgfgfgf”
validatorMessage=”fgfgf” immediate=”true”>
<f:validateLength maximum=”6000″ />
</p:editor>
<p:commandButton value=”Send” action=”#{questionBean.sendAnswer}” update=”:form” immediate=”true” />
</div>
Summary of questionBean:
private EntityQuestion selectedQuestion;
private String answer;
public EntityQuestion getSelectedQuestion() { return selectedQuestion; }
public void setSelectedQuestion(EntityQuestion newValue) { selectedQuestion = newValue; }
public String getAnswer() { return answer; }
public void setAnswer(String newValue) { answer = newValue; }
public void sendAnswer() {
……..
}
questionConverter:
public class QuestionConverter implements Converter {
public static EntityQuestion question = new EntityQuestion();
EntityManagerFactory emf = Persistence.createEntityManagerFactory(“ProjectPU”);
public EntityQuestion getAsObject(FacesContext context, UIComponent component, String value) {
EntityManager em = emf.createEntityManager();
Query query = em.createQuery(“SELECT s FROM EntityQuestion s WHERE s.url = :questionUrl”).setParameter(“questionUrl”, value);
question = (EntityQuestion) query.getSingleResult();
return question;
}
public String getAsString(FacesContext context, UIComponent component, Object value) {
EntityQuestion s = (EntityQuestion) value;
return s.getUrl();
}
}
when i open a question page first time everything works well. but when i remove immediate=”true” attribute from commandbutton on question.xhtml and add ajax=”false”, url goes wrong like that: “ProjectName.Question@19c4e4f” when i click. and questionConverter does not work. when i use immediate=”true” attribute, setAnswer setter does not getting called (maybe another problem cause to this but i don’t know and i can’t find !). maybe removing immediate=”true” attribute could be a solution. please help me.
May 9, 2012 at 9:23 pm #22531Hmm, nothing comes to mind. It sounds like maybe PrimeFaces is not correctly encoding the URL. Could you post the app and include steps to reproduce the problem, or create a new small sample app with minimal dependencies?
Thanks,
Lincoln
May 10, 2012 at 8:19 pm #22532my codes are in CountryBean2.java, country.xhtml and CountryConverter.java files. i use Netbeans 7.0.1, Glassfish 3.1.1 and Mysql 5.5.14. i uploaded all external libraries, project and database. i hope you will import easily.
May 10, 2012 at 8:34 pm #22533Hmm. Thank you for uploading! But, I should have just asked you to write a separate app that reproduces the issue without dependencies, sorry. That’s what I need

~Lincoln
May 10, 2012 at 9:13 pm #22534if you will run the app, i uploded all you need to hotfile. otherwise tomorrow i will write new app without using database and jpa. as i said, my issue is in CountryBean2.java, country.xhtml and CountryConverter.java. you can see these files in sampleproject.zip
May 10, 2012 at 9:54 pm #22535Please do, thanks so much!
June 4, 2012 at 6:47 pm #22536sorry for the late response, i was busy. i created new question class with simple java class, everything works well but is not working with Entity objects. did anybody try clean urls with jpa like as this sample ?
-
AuthorPosts
You must be logged in to reply to this topic.