How to print string in jsf Facelets page? [duplicate] - jsf

This question already has answers here:
javax.el.PropertyNotFoundException: The class 'xxx' does not have a readable property 'yyy'
(2 answers)
Closed 7 years ago.
(intro: I have generated Entity Clases from DB with one tabe lets say Beans, so it generated me Beans.java, BeansFacade.java, BeansController.java and AbstracFacade.java than I added JSF pages from entity classes, and just want to add something to list.xhtml)
In my BeansFacade.java I have
public String simple(){
return "output";
}
In BeansController.java I hava
public String printSimple(){
return ejbFacade.simple();
}
And than whem I try to print that
<h:outputText value="#{beansController.printSimple}"> </h:outputText>
I get an error
javax.el.PropertyNotFoundException:
The class 'fct.entity.EventsController' does not have the property 'printSimple'.

You are not able to call the method in h:outputText.
h:outputText tries to search the given variable related getter/setter
private String printSimple;
public String getPrintSimple()
{
return ejbFacade.simple();;
}
/**
* #return the simple
*/
public String getSimple()
{
return simple;
}
And than whem you can use the simple variable to get the value.
<h:outputText value="#{beansController.printSimple}"> </h:outputText>
before that call the printSimple method.

Related

how can i pass an url parameter between two xhtml pages? [duplicate]

This question already has answers here:
Does f:viewParam only pass query string in url when first page uses the same managed bean as the second page?
(2 answers)
Bookmarkability via View Parameters feature
(1 answer)
Closed 2 years ago.
i am trying to pass a parameter between two pages
in the bean i have this string with getters and setters
outcome is the function to run with the button
#Named("MeubleBean")
#ManagedBean
#SessionScoped
#RequestScoped
public class MeubleBean implements Serializable {
private String param1;
public String outcome() {
FacesContext fc = FacesContext.getCurrentInstance();
Map<String, String> params = fc.getExternalContext().getRequestParameterMap();
param1 = params.get("param1Name");
return "meubles3.jsf?faces-redirect=true&includeViewParams=true";
}
}
the code of the command button in the page meubles.xhtml :
<f:param id="param1" name="param1Name" value="param1Value"/>
</h:commandButton>
and finally the output in meubles3.xhtml :
<h:form><h:outputText value="#{meubleBean.param1}"></h:outputText>
</h:form>
i am trying the "param1value" as test value .
the output is always empty, i tried several ways none of em worked.
any solution please ???

attribute cannot be resolved as a member of bean (JSF) [duplicate]

This question already has answers here:
javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean
(6 answers)
Naming convention for getters/setters in Java
(7 answers)
Closed 2 years ago.
Hello i keep getting this warning for 4 attributes.
the one in the .xhtml is
First Name : <h:inputText value="#{projectBean.fname}" id="fname" required="true" requiredMessage=" Firstname is required"></h:inputText>
<h:message for="fname" styleClass="error"></h:message>
and the one in the bean is
private String fname;
public String getfName() {
return fname;
}
public void setfName(String fname) {
this.fname = fname;
}
the warning im getting
fname cannot be resolved as a member of projectBean
What seems to be the problem?

Real time validation for input box using Primefaces/JSF [duplicate]

This question already has an answer here:
How to validate availability of username in database?
(1 answer)
Closed 5 years ago.
I need to know if there is a way to do real-time validation using Primefaces/JSF?
My requirement looks simple:
I've an input box which would take only unique name. For eg.., if an user is looking to input an name which already exists in database, it
should throw error message like "User Name already exists." This
should happen as soon as the user has moved out of the input box
Reference can be inferred from Google registration page
I've spent a lot of time researching on internet but haven't arrived at any concrete solution.
I'm primarily looking for a solution in Primefaces/JSF. Is it possible?
You can do that with plain JSF. You just have to use a validator and add ajax behavior to your input field, e.g.
facelet
<h:form id="form">
<h:messages id="messages" />
<h:inputText value="#{anyBean.username}" validator="userValidator">
<f:ajax render="#this messages" />
</h:inputText>
</h:form>
validator
#FacesConverter("userValidator")
public class UserValidator implements Validator {
#Override
public void validate(FacesContext fc, UIComponent component, Object value) throws ValidatorException {
String username = (String) value;
if (usernameExists(username)) {
throw new ValidatorException(new FacesMessage("User Name already exists."));
}
}
private boolean usernameExists(String username) {
// check if username exists here
}
}
Of course you can also use the equivalent PrimeFaces components p:messages, p:inputText and p:ajax.

Parsing argument with JSF commandlink to managed bean [duplicate]

This question already has an answer here:
How to write a hardcoded string value inside EL expression #{ } in JSF?
(1 answer)
Closed 6 years ago.
I tried to parse argument with JSF to managed bean with ajax. my JSF code is this
<h:commandLink id="user" action="#{pageBean.setPage("user")}" >
user
<f:ajax execute="user" render="contentBody" />
</h:commandLink>
managed bean is this
#ManagedBean
public class PageBean {
private String path;
private String page;
public PageBean() {
}
#PostConstruct
public void init(){
path = "/WEB-INF/dashboard.xhtml";
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getPage() {
return page;
}
public void setPage(String page) {
this.page = page;
}
}
But when I run this I got following error. Why is that?
Error Parsing /WEB-INF/templete.xhtml: Error Traced[line: 37] Element type "h:commandLink" must be followed by either attribute specifications, ">" or "/>".
You are using double quotes in your attribute around user.
<h:commandLink id="user" action="#{pageBean.setPage("user")}" >
This results in templete.xml not beeing a valid XML-File.
Correct example line using single quotes (as proposed by #gWombat):
<h:commandLink id="user" action="#{pageBean.setPage('user')}" >
You should use simple quotes around the parameter user:
action="#{pageBean.setPage('user')}"

Setting list items in ice:SelectOneMenu [duplicate]

This question already has answers here:
How to populate options of h:selectOneMenu from database?
(5 answers)
Closed 2 years ago.
I wish to set items from a list to the selectonemenu in icefaces.
But when I do the same I get the following error:
java.lang.ClassCastException: cannot be cast to javax.faces.model.SelectItem
The is an entity class.
Please Help.
The normal way of creating and populating the selectOneMenu items would be the following:
private String selectedItem; // +getter +setter
private List<SelectItem> selectItems; // +getter
public Bean() {
selectItems = new ArrayList<SelectItem>();
for (Entity entity : getYourEntities()) {
selectItems.add(new SelectItem(entity.getValue(), entity.getLabel()));
}
}
With the following in the view (you can easily subsitite <h: with <ice:):
<h:selectOneMenu value="#{bean.selectedItem}">
<f:selectItems value="#{bean.selectItems}" />
</h:selectOneMenu>
Instead of a String value, you can also use any Number (Integer, Long, etc) since JSF has builtin converters for this. But if you want to use whole objects as item value, then you need to create a Converter. This is described in detail in this article.

Resources