File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Java Products and Servers and the fly likes FrontMan doesn't call usual bean-style setters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Other Java Products and Servers
Bookmark "FrontMan doesn Watch "FrontMan doesn New topic
Author

FrontMan doesn't call usual bean-style setters

Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

In normal bean programming, you tend to have a bunch of setters, setFoo(String arg) and setBaz(String arg) that are called with values from the POST arguments of the page (JSP, html, etc.).

In my work with FrontMan, this doesn't work. The setters are not called. The alternative works fine. You just get the argument map from the Context:

HashMap rMap = ctx.getRequest().getParameterMap();

and then query the HashMap for the paramaters. In many ways, I like this better than the old way, it avoids the large numbers of setters and getters that really don't do much. They are boilerplate, and killing boiler plate is good.

But, this approach leaves no documentation. There are no javadocs for the getters and setters to look at. All the work is done internally. I like documentation. I almost like writing it, because I sure like reading it.

How do I get FrontMan to call the traditional setFoo() functions?

Thanks
pat
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Pat Farrell wrote:How do I get FrontMan to call the traditional setFoo() functions?
On what?

Front Man itself doesn't provide any "form" capabilities out of the box (yet, see below). So I'm not sure what you'd be expecting it to call the setters and getters of. It's just not in FrontMan 1.x's charter.

If you want something easy, you can check out BeanUtils.populate() -- BeanUtils is a Jakarta project.

On the other hand...

Do I detect a volunteer to field test Front Man 2.0?

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Bear Bibeault wrote:On what?

Front Man itself doesn't provide any "form" capabilities out of the box (yet, see below). So I'm not sure what you'd be expecting it to call the setters and getters of. It's just not in FrontMan 1.x's charter.


Do I detect a volunteer to field test Front Man 2.0?

Sure, or even help create it.

What do you mean "on what?" I've got lots of commands, they get POSTed to. With arguments. So I use the HashMap to get the parameters. But it leaves nothing to be documented, see other thread on documenting for EL and forms.

So I'm not leaving any hints to the GUI designer of what paramters are needed.

Or perhaps you don't post to commands?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Pat Farrell wrote:What do you mean "on what?"
On what do the getters and setters exist? Pojo beans? The commands themselves? Either is possible, but I generally do the former.

Or perhaps you don't post to commands?
All the time. I then gather the parameters into Pojo beans -- not only for documentation purposes, but also to perform type conversions, as well as to create a neat and tidy bundle.

Pat Farrell wrote:
Bear Bibeault wrote:Do I detect a volunteer to field test Front Man 2.0?

Sure, or even help create it.
It's created. I've just been waiting to finish the documentation before publishing its availability.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Bear Bibeault wrote:
Pat Farrell wrote:What do you mean "on what?"
On what do the getters and setters exist? Pojo beans? The commands themselves? Either is possible, but I generally do the former.


I implement the command, with a proper @FrontmanCommand("usercontrolpanel") as a bean, implementing the execute() function.

Putting the setFoo() and setBas() on this class doesn't do much, they aren't invoked.

Perhaps I'm doing something wrong.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Pat Farrell wrote:Perhaps I'm doing something wrong.

Nope. As I said, Front Man 1.x doesn't provide anything automatic in this area. But you can achieve what you want by calling BeanUtils.populate() passing the target bean (which can be the command instance if you like) and the parameter map.

Front Man 2.0 has a plugin to make this even easier.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Bear Bibeault wrote: BeanUtils.populate()


What's a BeanUtils? Where can I find it. Not in the frontman jar that i've got

Answer: Apache Commons Beanutils.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

I already mentioned that it's a Jakarta project.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

sorry, I missed it the first time.

Calling BeanUtils in the base class of all my commands seems to work and its trivial to do.

Not sure how 2.0 can be much easier, but I'm all for easy.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Pat Farrell wrote:Not sure how 2.0 can be much easier, but I'm all for easy.

The optional plugin abstracts BeanUtils, and automates it via an annotation.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Also, be aware that BeanUtils is very finicky about the bean standard. Violate the least little thing about how the beans are defined and it just silently stops working.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Cool.

So when do you want me to start beta testing, writing documentation, etc.?

PM me if you want to move this off the forum.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Bear Bibeault wrote:Violate the least little thing about how the beans are defined and it just silently stops working.

got any examples to look out for?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Pat Farrell wrote:
Bear Bibeault wrote:Violate the least little thing about how the beans are defined and it just silently stops working.

got any examples to look out for?

Getters with no setters and vice versa.

Indexed properties are particularly finicky, but rare (thank goodness).
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Bear Bibeault wrote:Getters with no setters and vice versa.


Hmm, wonder if Frontman 2.1 could have a "validate my beans" function....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

Naw, that's what IDEs are for.
Pat Farrell
Rancher

Joined: Aug 11, 2007
Posts: 4646
    
    5

Bear Bibeault wrote: But you can achieve what you want by calling BeanUtils.populate() passing the target bean


I've found that this mostly works. But not always.

So the logical next step is to get the sources to BeanUtils, and step into the code. No joy. The short term problem is that the source jar package doesn't include all the required dependancies. That causes problems in Netbeans, my IDE du jour.

Checking the Beanutils pages say that it loves maven, so I install maven. Not too bad. But it doesn't seem to have all the interlocking pom files to make maven happy.

Further checking shows that BeanUtils is essentially dead. There was a new release recently, but it was after a five year hiatus. And the developers say frankly that new development has stopped.

So it looks like I may really need that beta of FrontMan to try out.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: FrontMan doesn't call usual bean-style setters