3

I've got very painful problem. Could not find solution on web.

I'm using Spring 3.0 with JSF and PrimeFaces Spring Security is configured, also have configuration for Spring Web Flow (but I'm not using it in this example).

Here is behavior I want to achieve: User choosing a value from p:selectOneMenu and it submits on change. Then the value is send for the Bean and it's being changed there as well. Effect: using p:selectOneMenu i changed value inside the userBean

After implementing all, I got an error which says:

    HTTP Status 405 - Request method 'POST' not supported

Select One Menu is written like that :

<f:view>
<h:form id="formUserChange"  >
<p:panelGrid columns="2">
<p:selectOneMenu id="chooseUserType" onchange="formUserChange.submit();" 
value="#{userBean.userType}" valueChangeListener="#{userBean.processValueChange}" 
style="padding: 0px 5px; font-size: 13px; width: 200px;" >
      <f:selectItem itemLabel="Option 1" itemValue="KO" />
      <f:selectItem itemLabel="Option 2" itemValue="KJ" />
</p:selectOneMenu>
</p:panelGrid>
</h:form>
</f:view>

Bean is placed like that:

   @ManagedBean(name = "userBean")
   @SessionScoped
   public class UserBean implements Serializable, ValueChangeListener {

private static final long serialVersionUID = 1L;

private String userName = "Michal";
private String userType = "WO";

public UserBean() {
}

public String getUserName() {
    System.out.println("I got now " + userType);
    return userName;
}

public void setUserName(String userName) {
    this.userName = userName;
}

public String getUserType() {
    return userType;
}

public void setUserType(String userType) {
    this.userType = userType;
    System.out.println("I set user as " + userType);
}

@Override
public void processValueChange(ValueChangeEvent arg0) throws AbortProcessingException {
    System.out.println("I have got " + userType);
}

    }

On one example I've found on web, guy said that valueChangeListener is not needed because value="#{userBean.userType}" will do the trick, but its not the issue here, I tried both with no effect.

The value is not changing at all. I know that bean works on the console but got errors on the console:

    18:09:26,565 INFO  [stdout] (http-localhost-127.0.0.1-8080-4) I got now WO

    18:09:28,537 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost-127.0.0.1-8080-4) Request method 'POST' not supported

And also I got the page (as mentioned at start):

    HTTP Status 405 - Request method 'POST' not supported

What do I missed ? Any annotation or sth ? I don't got a clue what's wrong

Jabi
  • 51
  • 1
  • 4

1 Answers1

0
  1. If you are using Spring Webflow then @ManagedBean annotation is not recommended - you will not be able to access Spring beans from it. Use @Component('userBean') and @Scope(value=WebApplicationContext.SCOPE_SESSION) instead. You will need to add Spring EL resolver to your config for Faces to be able to resolve your Spring beans, see http://static.springsource.org/spring/docs/3.0.x/api/org/springframework/web/jsf/el/SpringBeanFacesELResolver.html

  2. You dont need to submit the form in order to have backing bean values updated. Remove onchange="formUserChange.submit();". It is not a good practice to refer to JSF components by their IDs in JavaScript since these can change.

  3. If you dont need a value change listener you can just add ajax handler to have selectOneMenu update backing bean on change event:

<p:selectOneMenu id="chooseUserType" value="#{userBean.userType}" style="padding: 0px 5px; font-size: 13px; width: 200px;" >
      <f:selectItem itemLabel="Option 1" itemValue="KO" />
      <f:selectItem itemLabel="Option 2" itemValue="KJ" />
      <p:ajax event="change"/>
</p:selectOneMenu>
rootkit
  • 2,165
  • 2
  • 29
  • 43