Here's some ideas to try...
I see that you have a if statement in your JSP..
if(request.getContentLength() > 0) {
...
Are you sure this condition is true in your case? Otherwise the JSP
will never attempt to save the object.
If that's not it, you could always create a new JSP and just drop the
exact servlet code into the page via a scriptlet and work backwards
from there.
Hope this helps..
-Chris (Google)
On Jan 3, 2:50 am, webus <[email protected]> wrote:
> Hi to all! I have problem.
> I have JDO objects:
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class MenuButton {
> @PrimaryKey
> @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> private Long uid;
>
> @Persistent
> private String name;
>
> @Persistent(mappedBy="menuButton")
> private List<Topic> topicSets;
>
> @Persistent
> private boolean isEnabled;
>
> @Persistent
> private String toURL;
>
> public Long getUid() {
> return uid;
> }
>
> public void setUid(Long uid) {
> this.uid = uid;
> }
>
> public String getName() {
> return name;
> }
>
> public void setName(String name) {
> this.name = name;
> }
>
> public List<Topic> getTopicSets() {
> return topicSets;
> }
>
> public void setTopicSets(List<Topic> topicSets) {
> this.topicSets = topicSets;
> }
>
> public boolean isEnabled() {
> return isEnabled;
> }
>
> public void setEnabled(boolean isEnabled) {
> this.isEnabled = isEnabled;
> }
>
> public String getToURL() {
> return toURL;
> }
>
> public void setToURL(String toURL) {
> this.toURL = toURL;
> }
>
> }
>
> @PersistenceCapable(identityType = IdentityType.APPLICATION)
> public class Topic {
> @PrimaryKey
> @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
> private Key uid;
>
> @Persistent
> private MenuButton menuButton;
>
> @Persistent
> private String topicTheme;
>
> @Persistent
> private Text topicText;
>
> public Key getUid() {
> return uid;
> }
>
> public void setUid(Key uid) {
> this.uid = uid;
> }
>
> public MenuButton getMenuButton() {
> return menuButton;
> }
>
> public void setMenuButton(MenuButton menuButton) {
> this.menuButton = menuButton;
> }
>
> public String getTopicTheme() {
> return topicTheme;
> }
>
> public void setTopicTheme(String topicTheme) {
> this.topicTheme = topicTheme;
> }
>
> public Text getTopicText() {
> return topicText;
> }
>
> public void setTopicText(Text topicText) {
> this.topicText = topicText;
> }
>
> }
>
> I have Manager class to help me save or update data.
>
> public class Manager {
>
> PersistenceManager pm = null;
>
> public Manager() {
> pm = PMF.get().getPersistenceManager();
> }
>
> public PersistenceManager getPersistenceManager(){
> return pm;
> }
>
> public boolean Save(Object obj) {
> Transaction tx = null;
> try {
> tx = pm.currentTransaction();
> tx.begin();
> pm.makePersistent(obj);
> tx.commit();
> System.out.println("õÓÐÅÛÎÏ ÓÏÈÒÁÎÉÌÉ ÔÒÁÎÚÁËÃÉÀ!");
> return true;
> }
> catch(Exception ex) {
> System.out.println(ex.getMessage());
> System.out.println(ex.getLocalizedMessage());
> if(tx.isActive())
> tx.rollback();
> System.out.println("ïÔËÁÔÉÌÉ ÔÒÁÎÚÁËÃÉÀ ÐÏ
> ÉÓËÌÀÞÅÎÉÀ");
> return false;
> }
> }
>
> public boolean Delete(Object obj){
> Transaction tx = null;
> try {
> tx = pm.currentTransaction();
> tx.begin();
> pm.deletePersistent(obj);
> tx.commit();
> return true;
> }
> catch(Exception ex){
> System.out.println(ex.getMessage());
> return false;
> }
> finally {
> if(tx.isActive())
> tx.rollback();
> }
> }
>
> public Object getObjects(Object obj) {
> Query query = pm.newQuery(obj.getClass());
> Object reObj = query.execute();
> return reObj;
> }
>
> public Object getObjectById(Object obj, Long uid) {
> Object reObj = pm.getObjectById(obj.getClass(), uid);
> return reObj;
> }
>
> public Object executeJDOSQL(String sql){
> Object reObj = pm.newQuery(sql).execute();
> return reObj;
> }
>
> }
>
> I servlet i do some:
> String sql = String.format(
> "select from %s where name == '%s'"
> ,MenuButton.class.getName()
> ,"ôÅÓÔÙ");
> MenuButton selBut =
> ((List<MenuButton>)mgr.executeJDOSQL(sql)).get
> (0);
> Topic topic = new Topic();
> topic.setMenuButton(selBut);
> topic.setTopicText(new Text("ëÁËÏÊ ÔÏ ÔÁÍ ÔÅËÓÔ!"));
> topic.setTopicTheme("ëÁËÁÑ ÔÏ ÔÁÍ ÔÅÍÁ");
> System.out.println("óÏÈÒÁÎÑÅÍ");
> if(!mgr.Save(topic))
> System.out.println("ïÛÉÂËÁ!");
> It works OK!
>
> I try do the same code on JSP page:
>
> if(request.getContentLength() > 0) {
> String theme = request.getParameter("themeTitle");
> Text text = new Text(request.getParameter("themeBody"));
>
> String sql = String.format(
> "select from %s where name == '%s'"
> ,MenuButton.class.getName()
> ,"ôÅÓÔÙ");
> Manager mgr = new Manager();
> MenuButton selBut =
> ((List<MenuButton>)mgr.executeJDOSQL(sql)).get
> (0);
>
> Topic topic = new Topic();
> topic.setMenuButton(selBut);
> topic.setTopicText(text);
> topic.setTopicTheme(theme);
>
> if(!mgr.Save(topic))
> System.out.println("ïÛÉÂËÁ!");
> else System.out.println("óÏÈÒÁÎÉÌ!");
> }
>
> It works without errors, but nothing in database save.
> I can't understand where is my error!
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.