Announcement Announcement Module
No announcement yet.
Not allow field to update Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Not allow field to update

    Hello everyone,

    I am going mad with the following problem, a have a class named Service, with a relation ManyToOne to another class Company. This field is updated automatically on the Service Create using @PrePresist method. But i do not want a user to update this field, but being able to update every other field. The problem is that using on the jpsx render=false ou disabled=true, set the Roo controller to try to update the field with null.

    What is the best way to achieve this??

  • #2
    I suggest the spring reference guide.

    With the DataBinder you can specify which fields are ignored (disallowed fields) when updating the object (id for instance). That way you can disable/not render/only show the fields in your jsp...


    • #3
      I have done this:

      @RooWebScaffold(path = "services", formBackingObject = Service.class)
      public class ServiceController {

      public void initBinder(WebDataBinder binder) {

      And on update.jspx:

      <field:select disabled="true" field="company" id="c_com_gsell_domain_Service_company" itemValue="id" items="${companys}" path="/companys" z="FAktdDOsoWdwJazOUclK16W60d4="/>

      But on update, this is replacing the company with a null value....

      What am i doing wrong?


      • #4
        You would need to add the parent object in the session using @SessionAttributes


        • #5
          To me that indicates that a new object is being created instead of reusing the one used to display the page. YOu can either change this by adding @SessionAttributes and store the class in the session or you can create a @ModelAttribute annotated method which retrieves/returns the object (probably based on an id).

          I'm not that familiar with roo but maybe roo can helpyou in that regard (check the web actions/commands available).


          • #6
            Thank you all,

            but i am very new to Spring and Roo, i have 2 questions

            1 - the company object, is a reference from another object named AppUser, that i am using to authenticate users using Spring Security, i have read that it is possible to cast the UserDetails directly to my AppUser object, but this is raising an error : unable to cast etc... what are the prereq's for this direct cast?

            2 - Using @SessionAttributes can be very helpfull, i would like to store AppUser on this after the user login's, where can i do this?

            for storing automatically the company into the Service Object i am using this (as you can see this is NOT very good, using a direct cast would be much better:

            public void onPrePersist()
            Object principal = SecurityContextHolder.getContext().getAuthenticati on().getPrincipal();
            Company usercompany = new Company();
            if (principal instanceof UserDetails) {
            String userName = ((UserDetails) principal).getUsername();
            for (AppUser lappuser : AppUser.findAllAppUsers())
            if (lappuser.getName().equals(userName))
            usercompany = lappuser.getCompany();

            Thank you again for your help!


            • #7
              Without seeing more of your code I can not see why it is not working.

              We directly cast OK using the following code snippits

              if ((auth = SecurityContextHolder.getContext().getAuthenticati on()) != null) {
              userLoggedInProfile = (UserLoggedInProfile) auth.getPrincipal();

              public class UserLoggedInProfile implements Serializable, UserDetails {
              userLoggedInProfile is already in the Session so I am not sure why you want to "store AppUser on this after the user login using @SessionAttributes ". I could see you storing it in @SessionAttributes when an admin type user updates an AppUser object.


              • #8
                Thank you all,

                I have solved the problem, correcting my AppUser, AppRole classes to implement the apropriate Spring Security interfaces, now i can cast UserDetails to AppUser.

                great forum with great users, i will try to help others as i get more experience with Spring and Spring roo.