How to write a bean auto complete in wicket 1.4? - java

I want a bean auto complete.
I like the way the wicket DropDownChoice works.
We can add ChoiceRenderer to the DropDownChoice to display whatever we want.
And we can also set a bean object as the model object.
I want the auto complete to work exactly the same way.
I have tried it several times, but in vain.
I know there AbstactAutoCompleteRender and all, but I have always found that, the auto completes work well with Strings only.
So I have to convert my bean list to string list of some attribute of the bean and then do the auto complete logic, and then figure out the bean by doing some operations on the String (the model object).
It's working but, it's just too much of hustle for a thing, that can be easily done in DropDownChoice.
May be in latter version of wicket there is a bean auto complete, but is there any ways to achieve a simple bean auto complete in wicket 1.4.x?

wicket-extensions' Autocompleter works only with String as a model.
You can use https://github.com/wicketstuff/core/tree/core-1.4.x/jdk-1.5-parent/objectautocomplete-parent instead.

Related

Spring MVC: Bind Input field to multiple properties

I am trying to get Spring MVC to bind the value from one input field to multiple properties.
My use-case is a forum, that contains a form to create a new topic. That dialog actually create a topic and a post, which both have the same title, so only one input field exists for the title. If I copy the value myself in the controller method, using the "#Validated" annotation in the signature won't work, since the validator is called before I can copy the value, and so the title would still be missing in one field. Of course I can call the validator myself after copying the value, but if at all possible I would prefer if Spring would bind that value itself, just to get a clean solution (and to learn if and how it is possible).
Best regards,
Christian

Beans: How to properly manage a property affected by another one

I have an Entity/JSF Managed Bean Ticket that represents a helpdesk
ticket.
It has a status property; when the status is set to closed I want to
change the value of the closingDate property to the current system time.
But I think that code should be contained in the bean, as each time the
ticket is closed the time should be recorded.
What would be the proper way to manage it? I have several ideas.
Make setter of creationTime private, and change its value when the
status setter is called. Fast and quick, but makes a setter change two
attributes. Also, forces me to use JPA field access (not much of a problem
as I am already using it, but still a limitation) and I am not clear of
what will happen when the bean is serialized.
Make the status property a bound property as described in JavaBeans,
and make the class a PropertyChangeListener to itself. Very formal, but
a little overcomplicated to my likening.
Make setters for both properties private, and add a non-bean method
close() that performs both actions. I would go this way but it can make
me it complicated to work with JSF.
Do nothing. Keep the bean as dumb as it can and move the logic to the
controller; cross my fingers hoping that nobody forgets to update both
attributes.
I favour 1) or 3), but I would like to know if there is a better approach.
I don't know if anyone can tell you the proper way to manage it, as arguments can be made for many different approaches just like you make them. To add to your list as a combination of 1) and 3), for example:
Have the setter of status update creationTime when it status is set to closed and leave both setters public. Has benefits from both as I'm not aware of any downside to this from a JPA perspective.
What I would advice against however is having a Entity/JSF Managed Bean. I would recommend having two, an Entity bean and a JSF Managed Bean. This way your Entity bean can be kept as dumb as it can be, while your JSF Managed Bean will have smart methods like close() or reopen() and comprised of a series of dumb calls to the Entity bean. Also, you can do things like persist() in #PreDestroy. Easy to develop, easy to maintain, easy to make decisions. Hopefully you'll find this helpful.

Spring, create a bean from deserializing

I've not used Spring too much, so I might be missing something obvious. Anyway, this is the question:
Say you have a Spring managed bean that is a networking client. After you call a method on it you get some object back, say it is a List
Now I want to process that List into something more useful for the rest of my application, say it is of a MyBusinessBean type.
How do I avoid doing a
new MyBusinessBean(List<String> info)
?? If I do this it becomes an object that is not part of the context.
I'm doing something like:
MyBusinessBean myBean = (MyBusinessBean) applicationContext.getBean("myBusinessBean", info);
However I keep reading everywhere that this is a signal of something not being done properly, since I am making my code context aware. What is the proper Spring way of doing this?
The second way is what you do in Spring. Calling "new" means you're breaking the model.
But don't assume that every call to "new" is eliminated by Spring. Every object need not be under Spring's control. Sometimes you just gotta call "new", usually in the scope of a single method. Create the object, use it, GC it - no Spring bean factory needed.
If you want to give an object in your app access to that List after serialization, simply pass the reference. You don't need the Spring bean factory in the situation you've described, because you've already got the serialized the object from the server.

Java-Spring-Hibernate: How can I save a filter and, afterward, how could I use it?

I receive a task for a project which uses Spring, Hibernate and Wicket.
In a particular HTML page I must have the possibility to create a filter(set the name of the filter and its parameters). I must create a list of filters in this way.
In the same time, I must have the possibility to edit and delete the filter, and of course, to use that filter.
Any ideas? How could I do this?
if you're looking for a component to edit a list of items, then this might help: Building a ListEditor form component
you can use spring hibernate (or other ORM's) support to retrieve the data for your model without too much hassle.

Automatic entity mapping similar to O/R-mapping with JSF?

With JPA I do not need to code the SQL for every new attribute as the o/r-mapping is being done automatically.
As I am new to JSF, i am wondering whether there is a similar possiblity with JSF?
I do not want to add new code to a jsf datatable every time I change something at the corresponding entity.
JSF provides a way to manage events and the lifecycle of a request and its linked objects. Its always possible to use any ORM framework with it because JSF doesn't play directly with the database (it doesn't even know about it). Hibernate + JSF is a very common combination.
But if you are asking about using JSF managed beans with a JPA framework, have a look at Seam: http://www.seamframework.org/.
I do not want to add new code to a jsf datatable every time I change something at the corresponding entity.
If you want a dynamic datatable you will probably have to use an add-on to core JSF. I use IceFaces and it works very well. You can use the <ice:columns> component to generate columns dynamically. We use this to display the results of a query which may return different columns.

Categories